package it.hopeless.jee6.rest;

import javax.ejb.Stateless;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.Random;

/**
 * User: nbreda
 * Date: 17-feb-2010
 * Time: 19.23.36
 */
@Path("/hello")
@Stateless
@Produces("text/html")
public class RestHello {
    Random random = new Random();

    @Context
    UriInfo uriInfo;

    @GET
    public String getRandom(@DefaultValue("Nicola") @QueryParam("name") String name) {
        return "HELLO " + name;
    }

    @GET
    @Path("{name}")
    public String getHelloWithName(@PathParam("name") String name) {
        return "BUENAS DIAS " + name;
    }

    @GET
    @Path("/salut")
    public Response salut() throws MalformedURLException {
        URI uri = uriInfo.getBaseUriBuilder().path("/hello").build();
        System.out.println("URI = " + uri.toURL().toExternalForm());
        return Response.created(uri).status(302).build();
    }

}
